<template>
  <a-modal v-model:visible="visible" @ok="handleOk" @cancel="handleCancel">
    <template #title> 图标 </template>
    <div class="iconList">
      <div
        v-for="(v, i) in iconList"
        :key="i"
        class="iconItem"
        @click="chooseItemIcon(v)"
      >
        <img :src="v.url" alt="" />
        <span>{{ v.name }}</span>
      </div>
    </div>
  </a-modal>
</template>

<script setup>
  import { getListReq } from '@/api/icon/index';
  import { onMounted, ref } from 'vue';

  const emits = defineEmits(['update:modelValue']);

  const iconList = ref([]);

  const visible = ref(false);

  const openIconModal = () => {
    visible.value = true;
  };

  // const chooseItemIcon = (url) => {
  //   emits('update:modelValue', false);
  // };

  const chooseItemIcon = (v) => {
    emits('update:modelValue', v);
    visible.value = false;
  };

  defineExpose({
    openIconModal,
  });

  const iconData = ref({
    current: 1,
    size: 100,
  });
  onMounted(() => {
    getListReq(iconData.value).then((res) => {
      console.log(res);
      iconList.value = res.data.records;
    });
  });
</script>

<style lang="less" scoped>
  .iconList {
    display: flex;
    align-items: center;
    flex-wrap: wrap;

    .iconItem {
      width: 80px;
      height: 80px;
      margin-bottom: 24px;
      display: flex;
      flex-direction: column;
      align-items: center;
      img {
        width: 36px;
        height: 36px;
      }
    }
  }
</style>
